﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using SUT = Admx_Generator;

namespace Tests_Admx_Generator
{
    class Test_Category
    {
        [TestClass]
        public class Constructor_Should
        {
            [TestMethod]
            public void ProperlyInitializeTheNewInstance_WhenCalled()
            {
                // Arrange
                SUT.Category cat;
                string expectedName = "MyCategory";
                SUT.Reference expectedReference = null;
                string expectedDisplayName = "$(string." + expectedName + ")";
                string expectedExplainText = "$(string." + expectedName + "_Explain)";

                // Act
                cat = new SUT.Category(expectedName, expectedDisplayName, expectedExplainText, expectedReference);
                string actualName = cat.Name;
                SUT.Reference actualReference = cat.ParentCategory;
                string actualDisplayName = cat.DisplayName;
                string actualExplainText = cat.ExplainText;

                // Assert
                Assert.AreEqual(expectedName, actualName);
                Assert.AreEqual(expectedReference, actualReference);
                Assert.AreEqual(expectedDisplayName, actualDisplayName);
                Assert.AreEqual(expectedExplainText, actualExplainText);
            }

            [TestMethod]
            public void AutomaticallyGenerateADisplayName_WhenCalledWithoutDisplayName()
            {
                // Arrange
                SUT.Category cat;
                string expectedName = "MyCategory";
                SUT.Reference expectedReference = null;
                string expectedDisplayName = "$(string." + expectedName + ")";
                string expectedExplainText = "$(string." + expectedName + "_Explain)";

                // Act
                cat = new SUT.Category(expectedName, String.Empty, expectedExplainText, expectedReference);
                string actualName = cat.Name;
                SUT.Reference actualReference = cat.ParentCategory;
                string actualDisplayName = cat.DisplayName;
                string actualExplainText = cat.ExplainText;

                // Assert
                Assert.AreEqual(expectedName, actualName);
                Assert.AreEqual(expectedReference, actualReference);
                Assert.AreEqual(expectedDisplayName, actualDisplayName);
                Assert.AreEqual(expectedExplainText, actualExplainText);

            }
        }

        [TestClass]
        public class Equals_Should
        {
            [TestMethod]
            public void ReturnTrue_WhenNamesAreEqualsAndParentCategoryIsNull()
            {
                // Arrange
                SUT.Category firstCategory = new SUT.Category("First", "", "", null);
                SUT.Category secondCategory = new SUT.Category("First", "", "", null);

                // Assert
                Assert.IsTrue(firstCategory.Equals(secondCategory));
            }

            [TestMethod]
            public void ReturnFalse_WhenNamesAreDifferent()
            {
                // Arrange
                SUT.Category firstCategory = new SUT.Category("First", "", "", null);
                SUT.Category secondCategory = new SUT.Category("Second", "", "", null);

                // Assert
                Assert.IsFalse(firstCategory.Equals(secondCategory));
            }

            [TestMethod]
            public void ReturnFalse_WhenNamesAreEqualsAndParentCategoryAreDifferent()
            {
                // Arrange
                SUT.Category firstCategory = new SUT.Category("First", "", "", new SUT.Reference("first", "Component"));
                SUT.Category secondCategory = new SUT.Category("First", "", "", new SUT.Reference("second", "Component"));

                // Assert
                Assert.IsFalse(firstCategory.Equals(secondCategory));
            }

            [TestMethod]
            public void ReturnFalse_WhenNamesAreEqualsAndParentCategoryAreNullAndNotNull()
            {
                // Arrange
                SUT.Category firstCategory = new SUT.Category("First", "", "", null);
                SUT.Category secondCategory = new SUT.Category("First", "", "", new SUT.Reference("second", "Component"));

                // Assert
                Assert.IsFalse(firstCategory.Equals(secondCategory));
            }

            [TestMethod]
            public void ReturnTrue_WhenNamesAreEqualsAndParentCategoryAreEquals()
            {
                // Arrange
                SUT.Category firstCategory = new SUT.Category("First", "", "", new SUT.Reference("Component"));
                SUT.Category secondCategory = new SUT.Category("First", "", "", new SUT.Reference("Component"));

                // Assert
                Assert.IsTrue(firstCategory.Equals(secondCategory));
            }
        }
    }
}
